/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import * as fs from 'fs';
import * as path from 'path';

// 定义源目录和目标目录
const sourceDir = './node_modules/arkanalyzer/node_modules/ohos-typescript/lib';
const targetDir = 'resources/internalSdk/@internal';

// 定义需要拷贝的文件名集合
const filesToCopy = new Set([
  'lib.es2015.symbol.wellknown.d.ts',
  'lib.es5.d.ts',
  'lib.es2020.bigint.d.ts',
  'lib.es2017.sharedmemory.d.ts',
  'lib.es2015.collection.d.ts',
]);

// 确保目标目录存在
if (!fs.existsSync(targetDir)) {
  fs.mkdirSync(targetDir, { recursive: true });
}

// 遍历需要拷贝的文件名集合
filesToCopy.forEach(file => {
  const filePath = path.join(sourceDir, file);
  const stats = fs.statSync(filePath);

  if (stats.isFile()) {
    const targetPath = path.join(targetDir, file);
    fs.copyFileSync(filePath, targetPath);
    console.log(`Copied: ${file} to ${targetPath}`);
  } else {
    console.error(`File not found: ${file}`);
  }
});

console.log(`All specified files have been copied to ${targetDir}`);